<template>
  <div>
    <FilterTable
      ref="firsttable"
      :fetchapi="fetchApi1"
      :columns="columns1"
      :params="fetchParams1"
      :datakey="'rows'"
      :isSelectColumn="false"
      :onColumnsChange="columns1 => (this.columns1 = columns1)"
      :height="200"
      columnsRef="zjwxlssettlementTables1"
    ></FilterTable>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import exchanging from './exchanging.vue';
import { getWXXM, getWXCL, getXSCL, getFJXM } from '@/api/repair/business/customer/history';
import { querySellMaterial, queryChargeDifferentiationList } from '@/api/repair/repairReception/repairBusinessManger';
export default {
  name: 'zjsettlementTables',
  components: {
    exchanging
  },
  mixins: [dictionary],
  props: ['getdata'],
  data() {
    this.firsttable = null;
    return {
      fetchParams1: { RO_NO: this.getdata.RO_NO },
      columns1: this.createTable1(),
      fetchApi1: getXSCL,
      exchangingVisible: false,
      exchangingData: {
        RO_NO: this.getdata.RO_NO,
        ASC_SHORTNAME: this.getdata.ASC_SHORTNAME,
        projectName: '',
        assignLabourHour: '',
        troubleDesc: ''
      }
    };
  },
  mounted() {
    this.queryChargeList();
    this.querySellMaterial();
    this.querySeMaterial();
  },
  methods: {
    createTable1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          width: 150,
          sorter: true,
          filter: true,
          editable: false,
          defaultEditable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        // {
        //   title: '库位代码',
        //   dataIndex: 'STORAGE_POSITION_CODE',
        //   width: 150,
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '计量单位',
          dataIndex: 'UNIT_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件销售数量',
          dataIndex: 'PART_QUANTITY',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件成本金额',
          dataIndex: 'LABOUR_PRICE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '成本价',
          dataIndex: 'PART_COST_PRICE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否入账',
          dataIndex: 'IS_FINISHED',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.IS_FINISHED, '1004')}</span>;
          }
        }
      ];
    },
    closepop(val) {
      this.exchangingVisible = false;
    },
    async getcplistListFun() {
      const res = await getcplistList();
      // const response = await getqueryFeeList();
      // console.log('response', response);
      // this.columns[2].editItems = this.columns[2].filterItems = response.data.map(x => ({ text: x.MANAGE_SORT_NAME, value: x.MANAGE_SORT_CODE }));
      this.columns1.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = this.columns1.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').filterItems = res.data.map(x => ({
        text: x.CHARGE_PARTITION_NAME,
        value: x.CHARGE_PARTITION_CODE
      }));
    },
    // 查询收费区分
    async queryChargeList() {
      const res = await queryChargeDifferentiationList();
      // console.log(res, 'res');
      this.columns1.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = res.data.map(x => ({
        value: x.CHARGE_PARTITION_CODE + '',
        text: x.CHARGE_PARTITION_NAME
      }));
    },
    // 销售材料查询
    async querySeMaterial() {
      const roNo = this.roNo;
      // const res = await querySellMaterial(roNo);
      // console.log(res,'res')
      const res = (await querySellMaterial(roNo)).data.rows;
      this.saleStuffList = res;
    }
  }
};
</script>
